﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.AndonManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.AndonManagement.IssueRecordVMs
{
    public partial class IssueRecordListVM : BasePagedListVM<IssueRecord_View, IssueRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<IssueRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<IssueRecord_View>>{
                
                this.MakeGridHeader(x => x.IssueRecord_Station).SetTitle(@Localizer["Page.站点"].Value),
                this.MakeGridHeader(x => x.IssueRecord_OpId).SetTitle(@Localizer["Page.问题工位"].Value),
                this.MakeGridHeader(x => x.IssueRecord_OpName).SetTitle(@Localizer["Page.工位名称"].Value),
                this.MakeGridHeader(x => x.IssueRecord_IssueType).SetTitle(@Localizer["Page.问题类型"].Value),
                this.MakeGridHeader(x => x.IssueRecord_IssueTypeName).SetTitle(@Localizer["Page.问题名称"].Value),
                this.MakeGridHeader(x => x.IssueRecord_ReportTime).SetTitle(@Localizer["Page.上报时间"].Value),
                this.MakeGridHeader(x => x.IssueRecord_Reporter).SetTitle(@Localizer["Page.上报人"].Value),
                this.MakeGridHeader(x => x.IssueRecord_Description).SetTitle(@Localizer["Page.问题描述"].Value),
                this.MakeGridHeader(x => x.IssueRecord_Handler).SetTitle(@Localizer["Page.处理人"].Value),
                this.MakeGridHeader(x => x.IssueRecord_HandleTime).SetTitle(@Localizer["Page.处理时间"].Value),
                this.MakeGridHeader(x => x.IssueRecord_HandleResult).SetTitle(@Localizer["Page.处理结果"].Value),
                this.MakeGridHeader(x => x.IssueRecord_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.IssueRecord_Remark).SetTitle(@Localizer["Page.备用"].Value),
                this.MakeGridHeader(x => x.IssueRecord_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.IssueRecord_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.IssueRecord_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.IssueRecord_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<IssueRecord_View> GetSearchQuery()
        {
            var query = DC.Set<IssueRecord>()
                
                .CheckEqual(Searcher.StationId, x=>x.StationId)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpName, x=>x.OpName)
                .CheckEqual(Searcher.IssueTypeId, x=>x.IssueTypeId)
                .CheckContain(Searcher.IssueTypeName, x=>x.IssueTypeName)
                .CheckBetween(Searcher.ReportTime?.GetStartTime(), Searcher.ReportTime?.GetEndTime(), x => x.ReportTime, includeMax: false)
                .CheckContain(Searcher.Reporter, x=>x.Reporter)
                .CheckContain(Searcher.Description, x=>x.Description)
                .CheckContain(Searcher.Handler, x=>x.Handler)
                .CheckBetween(Searcher.HandleTime?.GetStartTime(), Searcher.HandleTime?.GetEndTime(), x => x.HandleTime, includeMax: false)
                .CheckContain(Searcher.HandleResult, x=>x.HandleResult)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new IssueRecord_View
                {
				    ID = x.ID,
                    
                    IssueRecord_Station = x.Station.TenantCode,
                    IssueRecord_OpId = x.OpId,
                    IssueRecord_OpName = x.OpName,
                    IssueRecord_IssueType = x.IssueType.TenantCode,
                    IssueRecord_IssueTypeName = x.IssueTypeName,
                    IssueRecord_ReportTime = x.ReportTime,
                    IssueRecord_Reporter = x.Reporter,
                    IssueRecord_Description = x.Description,
                    IssueRecord_Handler = x.Handler,
                    IssueRecord_HandleTime = x.HandleTime,
                    IssueRecord_HandleResult = x.HandleResult,
                    IssueRecord_Status = x.Status,
                    IssueRecord_Remark = x.Remark,
                    IssueRecord_CreateTime = x.CreateTime,
                    IssueRecord_UpdateTime = x.UpdateTime,
                    IssueRecord_CreateBy = x.CreateBy,
                    IssueRecord_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class IssueRecord_View: IssueRecord
    {
        
        public string IssueRecord_Station { get; set; }
        public long? IssueRecord_OpId { get; set; }
        public string IssueRecord_OpName { get; set; }
        public string IssueRecord_IssueType { get; set; }
        public string IssueRecord_IssueTypeName { get; set; }
        public DateTime? IssueRecord_ReportTime { get; set; }
        public string IssueRecord_Reporter { get; set; }
        public string IssueRecord_Description { get; set; }
        public string IssueRecord_Handler { get; set; }
        public DateTime? IssueRecord_HandleTime { get; set; }
        public string IssueRecord_HandleResult { get; set; }
        public IssueStatusEnum? IssueRecord_Status { get; set; }
        public string IssueRecord_Remark { get; set; }
        public DateTime? IssueRecord_CreateTime { get; set; }
        public DateTime? IssueRecord_UpdateTime { get; set; }
        public string IssueRecord_CreateBy { get; set; }
        public string IssueRecord_UpdateBy { get; set; }

    }

}